import {
	createArticle,
	getArticle,
	updateArticle,
	deleteArticle,
	uplaodArticle,
} from '../api/article';

export function useArticle() {
	const articleList = ref();
	const loading = ref(true);
	const createArticles = async (data: ArticleQuery) => {
		const res = await createArticle(data);
		return res;
	};
	const getArticles = async () => {
		loading.value = true;
		const res: AxiosResponse = await getArticle();
		articleList.value = res.result;
		loading.value = false;
	};
	const updateArticles = async (data: ArticleQuery) => {
		const res = await updateArticle(data);
		return res;
	};
	const deleteArticles = async (id: number) => {
		const res = await deleteArticle(id);
		return res;
	};
	const uplaodArticles = async (formdata: FormData) => {
		const res = await uplaodArticle(formdata);
		return res;
	};
	return {
		loading,
		articleList,
		createArticles,
		getArticles,
		updateArticles,
		deleteArticles,
		uplaodArticles,
	};
}
